home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibTextBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  2.7 KB  |  120 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. extern Display    *dpy;
  5. extern GC     mib_gc;
  6.  
  7. /* Code for TextBox */
  8. /*****************************************************************************/
  9.  
  10. mib_Widget *mib_create_TextBox(mib_Widget *parent, char *name, char *contents,
  11.     int posx, int posy, int width, int height,
  12.     int mib_fill)
  13. {
  14.   mib_Widget *temp;
  15.   mib_TextBox *myres;
  16.   Arg     args[20];
  17.   int     n;
  18.  
  19.   /* create the new widget and add it to the tree */
  20.  
  21.   temp = mib_new_mib_Widget();
  22.   if (mib_fill == WDEFAULT)
  23.     mib_add_backward(temp, parent);
  24.   else
  25.     mib_add_mib_Widget(temp, parent);
  26.   myres = (mib_TextBox *)malloc(sizeof(mib_TextBox));
  27.  
  28.   /* initialize public resources */
  29.  
  30.   if (mib_fill == WDEFAULT)
  31.   {
  32.     temp->name = (char *)malloc(strlen(name)+1);
  33.     strcpy(temp->name,name);
  34.   }
  35.   temp->mib_class = (char *)malloc(8);
  36.   sprintf(temp->mib_class,"TextBox");
  37.   temp->mib_class_num = MIB_TEXTBOX;
  38.   temp->width = width;
  39.   temp->height = height;
  40.   temp->topOffset = posy;
  41.   temp->leftOffset = posx;
  42.   temp->bottomOffset = 0;
  43.   temp->rightOffset = 0;
  44.   temp->topAttachment = 1;
  45.   temp->leftAttachment = 1;
  46.   temp->bottomAttachment = 0;
  47.   temp->rightAttachment = 0;
  48.  
  49.   temp->mib_allowresize = 1;
  50.  
  51.   /* initialize private resources */
  52.  
  53.   temp->myres = (void *)myres;
  54.   myres->init_contents = NULL;
  55.  
  56.   if (mib_fill == WDEFAULT)
  57.   {
  58.     if (contents != NULL)
  59.     {
  60.       myres->init_contents = (char *)malloc(strlen(contents)+1);
  61.       strcpy(myres->init_contents, contents);
  62.     }
  63.   }
  64.  
  65.   /* create Xt widget */
  66.  
  67.   n = 0;
  68.  
  69.   if (mib_fill == WDEFAULT)
  70.   {
  71.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  72.     XtSetArg (args[n], XmNleftOffset, posx);n++;
  73.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  74.     XtSetArg (args[n], XmNtopOffset, posy);n++;
  75.     XtSetArg (args[n], XmNwidth, width); n++;
  76.     XtSetArg (args[n], XmNheight, height); n++;
  77.   }
  78.  
  79.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  80.   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  81.  
  82.   temp->me = XtCreateManagedWidget(name, xmTextFieldWidgetClass,
  83.                 temp->parent->me, args, n);
  84.  
  85.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  86.   {
  87.     mib_apply_eventhandlers(temp->me, temp);
  88.     XmTextFieldSetString(temp->me, "Text Field");
  89.  
  90.   }
  91.  
  92.   return temp;
  93. }
  94.  
  95. void mib_delete_TextBox(mib_Widget *this)
  96. {
  97.   mib_TextBox *temp = (mib_TextBox *)this->myres;
  98.  
  99.   if (temp->init_contents != NULL)
  100.     free(temp->init_contents);
  101. }
  102.  
  103. void mib_save_TextBox(mib_Widget *this, FILE *fout)
  104. {
  105. }
  106.  
  107. int mib_load_TextBox(mib_Widget *this, mib_Buffer *fin)
  108. {
  109.   char          res[MI_MAXSTRLEN];
  110.   char          val[MI_MAXSTRLEN];
  111.  
  112.   if (!mib_read_line(fin, res, val))
  113.     return 0;
  114.  
  115.   if (!strcmp(res,"EndWidget."))
  116.     return 0;
  117.  
  118.   return 1;
  119. }
  120.